package cn.edu.scau.cmil.linwei.comprehensive.Controller;

import cn.edu.scau.cmil.linwei.comprehensive.Script.DataField;
import cn.edu.scau.cmil.linwei.comprehensive.Script.Score;
import cn.edu.scau.cmil.linwei.comprehensive.util.DataIO;
import cn.edu.scau.cmil.linwei.comprehensive.util.StageManager;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.beans.EventHandler;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TeacherInputWindowsController implements Initializable {

    public BorderPane borderPane;
    public Text CourseNameText;
    public Text TeacherNameText;
    public Text ClassNameText;
    public Text pageText;
    public Text TipText;
    public Text UserNameText;

    public Text StudentIDText1;
    public Text StudentNameText1;
    public TextField AttendInputTextField1;
    public TextField ExamInputTextField1;
    public TextField WorkInputTextField1;
    public TextField FinalExamInputTextField1;
    public Text TotalScoreText1;

    public Text StudentIDText2;
    public Text StudentNameText2;
    public TextField AttendInputTextField2;
    public TextField ExamInputTextField2;
    public TextField WorkInputTextField2;
    public TextField FinalExamInputTextField2;
    public Text TotalScoreText2;

    public Text StudentIDText3;
    public Text StudentNameText3;
    public TextField AttendInputTextField3;
    public TextField ExamInputTextField3;
    public TextField WorkInputTextField3;
    public TextField FinalExamInputTextField3;
    public Text TotalScoreText3;

    public Text StudentIDText4;
    public Text StudentNameText4;
    public TextField AttendInputTextField4;
    public TextField ExamInputTextField4;
    public TextField WorkInputTextField4;
    public TextField FinalExamInputTextField4;
    public Text TotalScoreText4;

    public Text StudentIDText5;
    public Text StudentNameText5;
    public TextField AttendInputTextField5;
    public TextField ExamInputTextField5;
    public TextField WorkInputTextField5;
    public TextField FinalExamInputTextField5;
    public Text TotalScoreText5;

    private String StudentCourse;//课名
    private String StudentGrade;//学生年级
    private String StudentMajor;//学生专业
    private String StudentClass;//学生班级号

    private ArrayList<Integer> searchedStudentData;//存储搜到的score结点在Arraylist中的下标
    private int searchedStudentDataNum;//搜到的score结点数目
    private int[] scorelistmark;//1~5分别存储当前五行数据的score结点在scorelist中的序号
    private int pagenum;//当前显示页面的页数

    //标题栏最小化、关闭、拖拽
    private double oldStageX,oldStageY,oldScreenX,oldScreenY;//点击时记录窗口的XY
    //最小化
    public void MinButtonClicked(){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.setIconified(true);
    }//设置最小化按钮点击时发生的活动选项
    //关闭
    public void CloseButtonClicked(){
        timer.cancel();
        saveThisPageInfo();//保存本页数据
        saveAllScoreData();//保存数据到文件
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.close();
    }//设置关闭按钮点击时发生的活动选项
    //鼠标拖拽
    public void MousePressed(MouseEvent event){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        oldStageX = stage.getX();//事件相对于MouseEvent源的原点的水平位置，即获取当前鼠标位置
        oldStageY = stage.getY();//事件相对于MouseEvent源的原点的垂直位置，即获取当前鼠标位置
        oldScreenX = event.getScreenX();//返回事件的绝对水平位置，即获取窗口左上角位置
        oldScreenY = event.getScreenY();//返回事件的绝对垂直位置，即获取窗口左上角位置
    }

    public void MouseDragged(MouseEvent event){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.setX(event.getScreenX()-oldScreenX+oldStageX);
        stage.setY(event.getScreenY()-oldScreenY+oldStageY);
    }


    //页面转换
    public void GoBack(){//返回教师主界面
        timer.cancel();
        saveThisPageInfo();//保存本页数据
        saveAllScoreData();//保存数据到文件
        CloseTeacherInputWindows();//关闭当前界面
        openTeacherMainWindows();//打开教师主界面
    }//注销

    public void openTeacherMainWindows() {
        Stage stage = StageManager.STAGEMAP.get("TeacherMainWindows");
        StageManager.STAGEMAP.remove("TeacherMainWindows");//在MAP中删除TeacherMainWindows页面的Stage
        StageManager.CONTROLLERMAP.remove("TeacherMainWindows");//在MAP中删除TeacherMainWindows页面的Controller
        stage.show();
    }//打开之前的程序主页面

    public void CloseTeacherInputWindows(){
        Stage stage = (Stage)borderPane.getScene().getWindow();//通过布局获取场景再获取舞台
        StageManager.STAGEMAP.put("TeacherInputWindows",stage);//保存舞台
        StageManager.CONTROLLERMAP.put("TeacherInputWindowsController",this);//保存控制器
        stage.close();//关闭舞台
    }//关闭当前页面

    //页面内容设定
    public void setUserNameText(String s)   { UserNameText.setText(s); };//设置用户名

    public void setCourseNameText(String s){
        CourseNameText.setText(s);
    }//设置课程名

    public void setTeacherNameText(String s){
        TeacherNameText.setText(s);
    }//设置教师名

    public void setClassNameText(String grade,String major,String classes){
        ClassNameText.setText(grade+"级"+major+"专业"+classes+"班");
    }//设置年级专业班级

    public void getCourseNameAndTeacherNameAndClassName(){
        TeacherMainWindowsController controller =//拿到教师主页面的控制器
                (TeacherMainWindowsController) StageManager.CONTROLLERMAP.get("TeacherMainWindowsController");
        StudentCourse = controller.getChoosedCourse();
        StudentGrade = controller.getChoosedGrade();
        StudentMajor = controller.getChoosedMajor();
        StudentClass = controller.getChoosedClass();
    }//通过控制器拿到课名、年级、专业、班级

    public void setCourseNameAndTeacherNameAndClassName(){
        getCourseNameAndTeacherNameAndClassName();
        setCourseNameText(StudentCourse);
        setTeacherNameText(DataField.LoginedUser.Name);
        setClassNameText(StudentGrade,StudentMajor,StudentClass);
    }//设置课名、教师名、班级名，调用上面的get获取信息后设置

    public void setTipText(String s){
        TipText.setText(s);
    }//设置Tip文字

    public void setPageText(int pagenum){
        String nowpage = String.valueOf(pagenum);
        String totalpage = String.valueOf(searchedStudentDataNum/5+1);
        pageText.setText(nowpage+"/"+totalpage);
    }

    //初始化方法
    public void initscorelistmark(){
        scorelistmark = new int[10];
        for(int i = 0;i<10;i++){//对mark数组进行清空
            scorelistmark[i] = -1;
        }
    }//初始化scorelistmark数组

    public void InitStudentDataTextField(){
        StudentIDText1.setText("");
        StudentNameText1.setText(" ");
        AttendInputTextField1.clear();
        ExamInputTextField1.clear();
        WorkInputTextField1.clear();
        FinalExamInputTextField1.clear();
        TotalScoreText1.setText("");
        AttendInputTextField1.setVisible(false);
        ExamInputTextField1.setVisible(false);
        WorkInputTextField1.setVisible(false);
        FinalExamInputTextField1.setVisible(false);

        StudentIDText2.setText("");
        StudentNameText2.setText(" ");
        AttendInputTextField2.clear();
        ExamInputTextField2.clear();
        WorkInputTextField2.clear();
        FinalExamInputTextField2.clear();
        TotalScoreText2.setText("");
        AttendInputTextField2.setVisible(false);
        ExamInputTextField2.setVisible(false);
        WorkInputTextField2.setVisible(false);
        FinalExamInputTextField2.setVisible(false);

        StudentIDText3.setText("");
        StudentNameText3.setText(" ");
        AttendInputTextField3.clear();
        ExamInputTextField3.clear();
        WorkInputTextField3.clear();
        FinalExamInputTextField3.clear();
        TotalScoreText3.setText("");
        AttendInputTextField3.setVisible(false);
        ExamInputTextField3.setVisible(false);
        WorkInputTextField3.setVisible(false);
        FinalExamInputTextField3.setVisible(false);

        StudentIDText4.setText("");
        StudentNameText4.setText(" ");
        AttendInputTextField4.clear();
        ExamInputTextField4.clear();
        WorkInputTextField4.clear();
        FinalExamInputTextField4.clear();
        TotalScoreText4.setText("");
        AttendInputTextField4.setVisible(false);
        ExamInputTextField4.setVisible(false);
        WorkInputTextField4.setVisible(false);
        FinalExamInputTextField4.setVisible(false);

        StudentIDText5.setText("");
        StudentNameText5.setText(" ");
        AttendInputTextField5.clear();
        ExamInputTextField5.clear();
        WorkInputTextField5.clear();
        FinalExamInputTextField5.clear();
        TotalScoreText5.setText("");
        AttendInputTextField5.setVisible(false);
        ExamInputTextField5.setVisible(false);
        WorkInputTextField5.setVisible(false);
        FinalExamInputTextField5.setVisible(false);
    }//初始化显示score的五行控件

    //查找score数据
    public void searchStudentData(){
        Score score;
        searchedStudentData = new ArrayList<>();//不初始化会报错
        searchedStudentDataNum = 0;
        String teacherName = DataField.LoginedUser.Name;
        for(int i = 0; i<DataField.scoreData.size(); i++){
            score = DataField.scoreData.get(i);
            if(score.CourseName.equals(StudentCourse) && score.TeacherName.equals(teacherName)
                    && score.StudentGrade.equals(StudentGrade)
                    && score.StudentMajor.equals(StudentMajor)
                    && score.StudentClass.equals(StudentClass)){//如果课名、老师名、年级、专业一致
                searchedStudentData.add(i);//加入数组中
                searchedStudentDataNum++ ;
            }
        }//for
    }//根据老师名、课名、年级专业班级查找学生信息，并存入数组searchedStudentData中
    //显示score数据
    public void showStudentData(int pagenum){
        InitStudentDataTextField();//先对所有TextField进行清空操作并且设为不可见
        initscorelistmark();//对scorelist数组初始化为-1
        //第一页：0~4
        //第二页：5~9
        //第三页：10~14
        // ···
        for(int i = 5*(pagenum-1) ; i<searchedStudentData.size() && i<5*pagenum ; i++){
            int scoreLocation = searchedStudentData.get(i);//scoreLocation代表score数据在Arraylist中的位置
            Score score = DataField.scoreData.get(scoreLocation);
            scorelistmark[i%5] = scoreLocation;//存储第i个score在Arraylist中的位置
            switch(i%5){
                case 0:StudentIDText1.setText(score.StudentID);
                            StudentNameText1.setText(score.StudentName);
                            AttendInputTextField1.setText(String.valueOf(score.Attend));
                            ExamInputTextField1.setText(String.valueOf(score.Exam));
                            WorkInputTextField1.setText(String.valueOf(score.Work));
                            FinalExamInputTextField1.setText(String.valueOf(score.FinalExam));
                            TotalScoreText1.setText(String.valueOf(score.TotalScore));
                            AttendInputTextField1.setVisible(true);
                            ExamInputTextField1.setVisible(true);
                            WorkInputTextField1.setVisible(true);
                            FinalExamInputTextField1.setVisible(true);
                            break;
                case 1:StudentIDText2.setText(score.StudentID);
                            StudentNameText2.setText(score.StudentName);
                            AttendInputTextField2.setText(String.valueOf(score.Attend));
                            ExamInputTextField2.setText(String.valueOf(score.Exam));
                            WorkInputTextField2.setText(String.valueOf(score.Work));
                            FinalExamInputTextField2.setText(String.valueOf(score.FinalExam));
                            TotalScoreText2.setText(String.valueOf(score.TotalScore));
                            AttendInputTextField2.setVisible(true);
                            ExamInputTextField2.setVisible(true);
                            WorkInputTextField2.setVisible(true);
                            FinalExamInputTextField2.setVisible(true);
                            break;
                case 2:StudentIDText3.setText(score.StudentID);
                            StudentNameText3.setText(score.StudentName);
                            AttendInputTextField3.setText(String.valueOf(score.Attend));
                            ExamInputTextField3.setText(String.valueOf(score.Exam));
                            WorkInputTextField3.setText(String.valueOf(score.Work));
                            FinalExamInputTextField3.setText(String.valueOf(score.FinalExam));
                            TotalScoreText3.setText(String.valueOf(score.TotalScore));
                            AttendInputTextField3.setVisible(true);
                            ExamInputTextField3.setVisible(true);
                            WorkInputTextField3.setVisible(true);
                            FinalExamInputTextField3.setVisible(true);
                            break;
                case 3:StudentIDText4.setText(score.StudentID);
                            StudentNameText4.setText(score.StudentName);
                            AttendInputTextField4.setText(String.valueOf(score.Attend));
                            ExamInputTextField4.setText(String.valueOf(score.Exam));
                            WorkInputTextField4.setText(String.valueOf(score.Work));
                            FinalExamInputTextField4.setText(String.valueOf(score.FinalExam));
                            TotalScoreText4.setText(String.valueOf(score.TotalScore));
                            AttendInputTextField4.setVisible(true);
                            ExamInputTextField4.setVisible(true);
                            WorkInputTextField4.setVisible(true);
                            FinalExamInputTextField4.setVisible(true);
                            break;
                case 4:StudentIDText5.setText(score.StudentID);
                            StudentNameText5.setText(score.StudentName);
                            AttendInputTextField5.setText(String.valueOf(score.Attend));
                            ExamInputTextField5.setText(String.valueOf(score.Exam));
                            WorkInputTextField5.setText(String.valueOf(score.Work));
                            FinalExamInputTextField5.setText(String.valueOf(score.FinalExam));
                            TotalScoreText5.setText(String.valueOf(score.TotalScore));
                            AttendInputTextField5.setVisible(true);
                            ExamInputTextField5.setVisible(true);
                            WorkInputTextField5.setVisible(true);
                            FinalExamInputTextField5.setVisible(true);
                            break;
                default:break;//如果超过五个，break
            }//switch
        }//for

    }//显示五行score
    //界面翻页【需要在翻页时保存本页数据到内存里】
    public void previousPage(){
        if(pagenum == 1){//第一页无法向前翻页
            return;
        }
        if(saveThisPageInfo() == false){
            return;
        }
        setTipText("");
        pagenum--;
        setPageText(pagenum);
        showStudentData(pagenum);
    }//点击上一页按钮，翻页

    public void nextPage(){
        if(pagenum == searchedStudentDataNum/5+1){//最后一页无法向前翻页
            return;
        }
        if(saveThisPageInfo() == false){
            return;
        }
        setTipText("");
        pagenum++;
        setPageText(pagenum);
        showStudentData(pagenum);
    }//点击下一页按钮，翻页

    //数据输入检测
    public boolean CheckTotalScoreIsOk(String totalscore){
        //使用正则表达式进行匹配判断
        if(totalscore.equals("")){
            return false;
        }
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher matcher = pattern.matcher(totalscore);
        if(matcher.matches()){//如果字符串是数字，查看范围
            int ts = Integer.parseInt(totalscore);
            if(0<=ts && ts<=100){
                return true;//如果在0~100，返回真
            }
        }
        setTipText("您输入的成绩非法");
        return false;
    }//0~100的数字，返回true，否则false

    public boolean InputisNumber(String tmp){
        //使用正则表达式进行匹配判断
        if(tmp.equals("")){
            return false;
        }
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher matcher = pattern.matcher(tmp);
        if(matcher.matches()){//如果字符串是数字，返回真
            return true;
        }
        setTipText("您的输入非法");
        return false;
    }//字符串是数字，返回true，否则返回false

    //保存score数据
    //可以撤销保存按钮，首先实时更新本页数据到内存，再对标题栏进行重做，只要点击退出程序或返回上一页都进行文件读写即可
    public boolean saveScoreData(String Attend,String Exam,String Work,String FinalExam,int scorelocation){
        if(InputisNumber(Attend) && InputisNumber(Exam) &&InputisNumber(Work) &&InputisNumber(FinalExam)){
            int attend = Integer.valueOf(Attend);
            int exam = Integer.valueOf(Exam);
            int work = Integer.valueOf(Work);
            int finalexam = Integer.valueOf(FinalExam);
            int totalscore = attend + exam + work + finalexam;
            if(CheckTotalScoreIsOk(String.valueOf(totalscore))){
                Score sc = DataField.scoreData.get(scorelocation);
                sc.Attend = attend;//更改引用中的Attend，Arraylist中的Attend会改变
                sc.Exam = exam;
                sc.Work = work;
                sc.FinalExam = finalexam;
                sc.TotalScore = totalscore;
                System.out.println(Attend+" "+Exam+" "+Work+" "+FinalExam+" "+scorelocation+" ");
                return true;
            }//if
        }
        return false;
    }//保存成功，返回true，否则返回false

    public boolean saveThisPageInfo(){
        if(scorelistmark[0] != -1){//如果有第一个score
            String Attend = AttendInputTextField1.getText();
            String Exam = ExamInputTextField1.getText();
            String Work = WorkInputTextField1.getText();
            String FinalExam = FinalExamInputTextField1.getText();
            System.out.println("第1行");
            if(saveScoreData(Attend,Exam,Work,FinalExam,scorelistmark[0]) == false){
                //如果这一行保存失败，这一行的总评变成红色
                TotalScoreText1.setFill(Color.RED);
                return false;
            }
            //如果保存成功，总评变成黑色
            TotalScoreText1.setFill(Color.WHITE);
        }//if

        if(scorelistmark[1] != -1){//如果有第二个score
            String Attend = AttendInputTextField2.getText();
            String Exam = ExamInputTextField2.getText();
            String Work = WorkInputTextField2.getText();
            String FinalExam = FinalExamInputTextField2.getText();
            System.out.println("第2行");
            if(saveScoreData(Attend,Exam,Work,FinalExam,scorelistmark[1]) == false){
                //如果这一行保存失败，这一行的总评变成红色
                TotalScoreText2.setFill(Color.RED);
                return false;
            }
            //如果保存成功，总评变成黑色
            TotalScoreText2.setFill(Color.WHITE);
        }//if

        if(scorelistmark[2] != -1){//如果有第三个score
            String Attend = AttendInputTextField3.getText();
            String Exam = ExamInputTextField3.getText();
            String Work = WorkInputTextField3.getText();
            String FinalExam = FinalExamInputTextField3.getText();
            System.out.println("第3行");
            if(saveScoreData(Attend,Exam,Work,FinalExam,scorelistmark[2]) == false){
                //如果这一行保存失败，这一行的总评变成红色
                TotalScoreText3.setFill(Color.RED);
                return false;
            }
            //如果保存成功，总评变成黑色
            TotalScoreText3.setFill(Color.WHITE);
        }//if

        if(scorelistmark[3] != -1){//如果有第四个score
            String Attend = AttendInputTextField4.getText();
            String Exam = ExamInputTextField4.getText();
            String Work = WorkInputTextField4.getText();
            String FinalExam = FinalExamInputTextField4.getText();
            System.out.println("第4行");
            if(saveScoreData(Attend,Exam,Work,FinalExam,scorelistmark[3]) == false){
                //如果这一行保存失败，这一行的总评变成红色
                TotalScoreText4.setFill(Color.RED);
                return false;
            }
            //如果保存成功，总评变成黑色
            TotalScoreText4.setFill(Color.WHITE);
        }//if
        if(scorelistmark[4] != -1){//如果有第五个score
            String Attend = AttendInputTextField5.getText();
            String Exam = ExamInputTextField5.getText();
            String Work = WorkInputTextField5.getText();
            String FinalExam = FinalExamInputTextField5.getText();
            System.out.println("第5行");
            if(saveScoreData(Attend,Exam,Work,FinalExam,scorelistmark[4]) == false){
                //如果这一行保存失败，这一行的总评变成红色
                TotalScoreText5.setFill(Color.RED);
                return false;
            }
            //如果保存成功，总评变成黑色
            TotalScoreText5.setFill(Color.WHITE);
        }//if
        return true;
    }//有任何一行没有保存成功都返回false
    // 保存本页数据至内存，调用上面的saveScoreData();
    // 如果有输入框的内容异常，requestfocus请求焦点并且阴影设为红色

    public void saveAllScoreData(){
        try{
            DataIO.ScoreWrite();
        }
        catch (IOException e){
            System.out.println(e);
        }
    }//执行文件写入，将内存中的scoredata写入文件，以实现数据的实际修改

    //界面实时刷新
    public void updateTotalscoreText(){
        if(scorelistmark[0] != -1){//如果有第一个score
            String Attend = AttendInputTextField1.getText();
            String Exam = ExamInputTextField1.getText();
            String Work = WorkInputTextField1.getText();
            String FinalExam = FinalExamInputTextField1.getText();
            if(InputisNumber(Attend) && InputisNumber(Exam) &&
                    InputisNumber(Work) && InputisNumber(FinalExam)){
                int totalScore = Integer.valueOf(Attend)+Integer.valueOf(Exam)+Integer.valueOf(Work)+Integer.valueOf(FinalExam);
                TotalScoreText1.setText(String.valueOf(totalScore));
            }
        }//if

        if(scorelistmark[1] != -1){//如果有第二个score
            String Attend = AttendInputTextField2.getText();
            String Exam = ExamInputTextField2.getText();
            String Work = WorkInputTextField2.getText();
            String FinalExam = FinalExamInputTextField2.getText();
            if(InputisNumber(Attend) && InputisNumber(Exam) &&
                    InputisNumber(Work) && InputisNumber(FinalExam)){
                int totalScore = Integer.valueOf(Attend)+Integer.valueOf(Exam)+Integer.valueOf(Work)+Integer.valueOf(FinalExam);
                TotalScoreText2.setText(String.valueOf(totalScore));
            }
        }//if

        if(scorelistmark[2] != -1){//如果有第三个score
            String Attend = AttendInputTextField3.getText();
            String Exam = ExamInputTextField3.getText();
            String Work = WorkInputTextField3.getText();
            String FinalExam = FinalExamInputTextField3.getText();
            if(InputisNumber(Attend) && InputisNumber(Exam) &&
                    InputisNumber(Work) && InputisNumber(FinalExam)){
                int totalScore = Integer.valueOf(Attend)+Integer.valueOf(Exam)+Integer.valueOf(Work)+Integer.valueOf(FinalExam);
                TotalScoreText3.setText(String.valueOf(totalScore));
            }
        }//if

        if(scorelistmark[3] != -1){//如果有第四个score
            String Attend = AttendInputTextField4.getText();
            String Exam = ExamInputTextField4.getText();
            String Work = WorkInputTextField4.getText();
            String FinalExam = FinalExamInputTextField4.getText();
            if(InputisNumber(Attend) && InputisNumber(Exam) &&
                    InputisNumber(Work) && InputisNumber(FinalExam)){
                int totalScore = Integer.valueOf(Attend)+Integer.valueOf(Exam)+Integer.valueOf(Work)+Integer.valueOf(FinalExam);
                TotalScoreText4.setText(String.valueOf(totalScore));
            }
        }//if
        if(scorelistmark[4] != -1){//如果有第五个score
            String Attend = AttendInputTextField5.getText();
            String Exam = ExamInputTextField5.getText();
            String Work = WorkInputTextField5.getText();
            String FinalExam = FinalExamInputTextField5.getText();
            if(InputisNumber(Attend) && InputisNumber(Exam) &&
                    InputisNumber(Work) && InputisNumber(FinalExam)){
                int totalScore = Integer.valueOf(Attend)+Integer.valueOf(Exam)+Integer.valueOf(Work)+Integer.valueOf(FinalExam);
                TotalScoreText5.setText(String.valueOf(totalScore));
            }
        }//if
    }
    Timer timer;
    public void update(){

        TimerTask ts;
        Runnable runnable;

        runnable = new Runnable() {
            @Override
            public void run() {
                updateTotalscoreText();
            }
        };

        ts = new TimerTask() {
            @Override
            public void run() {
                Platform.runLater(runnable);//在非FX线程中执行FX线程相关的任务，必须在Platform.runlater中执行
            }
        };

        timer = new Timer();
        timer.schedule(ts,0,500);

    }//建立新线程执行相关的操作

    public void setWelcome(){
        UserNameText.setText("");
    }


    @Override
    public void initialize(URL location, ResourceBundle resources) {

        setCourseNameAndTeacherNameAndClassName();
        setUserNameText(DataField.LoginedUser.Name);

        searchStudentData();//搜索符合条件的score

        initscorelistmark();//初始化score数组

        setTipText("共搜索到"+String.valueOf(searchedStudentDataNum)+"条学生信息");//展示搜索到的score数量

        pagenum = 1;
        setPageText(pagenum);
        showStudentData(pagenum);//自showedStudentDataNum起，展示五个score

        update();
    }
}
